﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web.Mvc;
using Management.BLL;
using Util.Webs.EasyUi.Trees;
using Util.Webs.EasyUi.Results;
namespace MET.Web.Controllers
{
    public class adminController : BaseController
    {
        //
        // GET: /admin/
        [Description("[Index首页]系统管理")]
        [DefaultPage]
        [ViewPage]
        public ActionResult Index()
        {
            if (Session["UserID"] == null)
                return RedirectToAction("index", "login");
            else
            return View();
        }
        [Anonymous]
        public ActionResult Error()
        {
            return View();
        }
        [Anonymous]
        public ActionResult LoadTree()
        {
                    string s = @"";
                    return  this.Content(s);
        }
        #region 菜单
        /// <summary>
        /// 获取菜单
        /// </summary>
        /// <returns></returns>
        [Description("[Index首页Load菜单树]获取菜单信息")]
        [LoginAllowView]
        [UIExceptionResult]
        public ActionResult GetMenus()
        {
            ModuleService service = new ModuleService();
            CurrentUserHelper CurrentUser = new CurrentUserHelper();
            var listmodules= service.GetAllModules();
            var firstmodules = listmodules.Where(q => q.ParentID == 0);
            List<TreeNode> listtreenode = new List<TreeNode>();
            foreach (var item in firstmodules)
            {
                var node = new TreeNode { Id = item.MID.ToString(), Text =item .ModuleName  };
                listtreenode.Add(node);
            }
            var chiledmodules = listmodules.Where(q => q.ParentID >0);
            foreach (var item in chiledmodules)
            {
                var node = new TreeNode { Id = item.MID.ToString(), ParentId = item.ParentID.ToString(), Text = item.ModuleName, Attributes = new { url = item.ModuleLinkUrl } };
                listtreenode.Add(node);
            }
            return Content(new TreeResult(listtreenode).ToString());
        }
        #endregion
        
    }
}
